#include <iostream>
#include <vector>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
const int N=810;

int n,p,c;
vector<pair<int,int>> edge[N];
int cnt[N];
int vis[N];
int dist[N];
struct cmp{
	bool operator()(const pair<int,int>&p1,const pair<int,int>&p2)
	{
		if(p1.second==p2.second)
		{
			return p1.first>p2.first;
		}
		return p1.second>p2.second;
	}
};
int dijkstra(int u)
{

	for(int i=1;i<=p;i++)
	{
		vis[i]=0;
		dist[i]=0x3f3f3f3f;
	}
	priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
	q.push({u,0});
	dist[u]=0;
	while(q.size())
	{
		int x=q.top().first;
		q.pop();
		if(vis[x])
			continue;
		vis[x]=1;
		
		for(auto& e:edge[x])
		{
			if(dist[e.first]>dist[x]+e.second){
				dist[e.first]=dist[x]+e.second;
				q.push({e.first,dist[e.first]});				
			}	
		}
		
	}
	int ret=0;
	for(int i=1;i<=p;i++)
	{
		if(cnt[i] && dist[i]==0x3f3f3f3f)
			return 0x3f3f3f3f;
		ret+=dist[i]*cnt[i];
	}
	return ret;
}
int main()
{
	cin>>n>>p>>c;
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		cnt[t]++;
	}
	for(int i=0;i<c;i++)
	{
		int a,b,d;
		cin>>a>>b>>d;
		edge[a].push_back({b,d});
		edge[b].push_back({a,d});
	}	
	int ret=0x3f3f3f3f;
	for(int i=1;i<=p;i++)
	{
		int t=dijkstra(i);
		ret=min(ret,t);
	}
	cout<<ret<<endl;
	return 0;
}
